package com.dahua.simplefactory.version4;

/**
 * 简单工厂模式：
 * 1. 这个简单工厂类的作用是根据运算符的种类创建对应的运算类；
 * 2. 此简单工厂类OperationFactory依赖抽象类Operation(即，这个简单工厂类的实现需要依赖抽象类Operation和其具体的子类
 * OperationAdd、OperationSub、OperationMul、OperationDiv、OperationSqrt的协助)
 *
 * @author sunhongguang
 * @create 2022-01-09-12:05
 */
public class OperationFactory {

    public static Operation createOperate(String opearte) {
        Operation operation = null;
        switch (opearte) {
            case "+":
                operation = new OperationAdd();
                break;
            case "-":
                operation = new OperationSub();
                break;
            case "*":
                operation = new OperationMul();
                break;
            case "/":
                operation = new OperationDiv();
                break;
            case "√":
                operation = new OperationSqrt();
                break;
            default:
                throw new RuntimeException("不支持的运算操作" + "[" + opearte + "]");
        }
        return operation;
    }
}
